package Offer.offer2022;

import domain.ListNode;

/**
 * 反转链表
 */
public class Test16 {
    public static ListNode reverseListNode(ListNode head) {
        if (head == null) {
            return null;
        }

        ListNode p1 = head;
        ListNode p2 = head.next;
        head.next = null;
        while (p2 != null) {
            ListNode p3 = p2.next;
            p2.next = p1;
            p1 = p2;
            p2 = p3;
        }
        return p1;
    }
}
